package com.scitc.controller;

import com.scitc.model.HistoryItem;
import com.scitc.model.Result;
import com.scitc.service.HistoryService;
import com.scitc.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.util.Date;

/**
 * @author: zk
 * @date: 2021/7/11 0:58
 * @description: null
 */
@RestController
public class MatchHistoryController {

    @Autowired
    HistoryService historyService;

    @Autowired
    JwtUtil jwtUtil;

    @PostMapping("/findallhis")
    public Result findAllHis(@RequestParam(value = "token", required = false) String token) {

        //检测是否登录
        if (token == null) {
            return Result.fail("登录后才能使用该功能");
        }

        // 验证token是否有效
        switch (jwtUtil.verify(token)) {
            case 2:
                return Result.fail("令牌已经过期");
            case 0:
                return Result.fail("令牌无效");
        }

        return Result.success("查询成功", historyService.findAllHis((String) jwtUtil.analysis(token).get("id")));
    }

}
